import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-10-20
 * Time: 19:11
 */

class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
}

public class Solution {
    public Map<Integer,Employee> map=new HashMap<>();
    public int getImportance(List<Employee> employees, int id) {
        //先得到每个员工的id和重要性
        for(int i=0;i<employees.size();i++){
            Employee employee=employees.get(i);
            map.put(employee.id,employee);
        }
        int result=dfs(id);
        return result;
    }

    //深度优先遍历
    private int dfs(int id){
        int result=map.get(id).importance;
        List<Integer> list=map.get(id).subordinates;
        int size=list.size();
        for(int i=0;i<size;i++){
            result+=dfs(list.get(i));
        }
        return result;
    }
}
